import Axios from 'axios'
import { ElNotification } from 'element-plus'
import 'element-plus/es/components/notification/style/css'
Axios.defaults.baseURL = import.meta.env.VITE_APP_BASE_API
Axios.defaults.timeout = 60000
Axios.interceptors.response.use(
  (res) => {
    return res.data?.data || res.data
  },
  (err) => {
    if (err.status >= 400 && err.status < 500) {
      if (err.response?.data?.message) {
        ElNotification.warning(err.response.data.message)
        return Promise.resolve(err.response.data.message)
      }
    }
    ElNotification.error('服务器错误请联系管理员！')
    return Promise.reject(err)
  },
)
Axios.interceptors.request.use((config) => {
  return config
})
export default Axios
